package com.yangcheng.web.scheduletask;

import com.yangcheng.dao.StatisticMapper;
import com.yangcheng.utils.MailUtils;
import com.yangcheng.utils.MyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduleTask {
    @Autowired
    private StatisticMapper statisticMapper;
    @Autowired
    private MailUtils mailUtils;
    @Value("${spring.mail.username}")
    private String mailto;
    @Scheduled(cron = "0 19 21 27 4 * ")
    public void senmail(){
        long totalfangwen=statisticMapper.getTotalVisit();
        long totalpinglun=statisticMapper.getTotalComment();
        StringBuffer buffer = new StringBuffer();
        buffer.append("文章总访问量"+totalfangwen+"人次").append("\n");
        buffer.append("文章总评论量"+totalpinglun+"人次").append("\n");
        mailUtils.sendSimpleEmail(mailto,"个人博客",buffer.toString());
    }

}
